package com.blog.controller;

import com.blog.common.CommonRespDto;
import com.blog.common.RespBean;
import com.blog.service.BaseRoleService;
import com.blog.system.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName BaseRoleController
 * @Destription 权限
 * @Author 天堂小野花
 * @Date 2025/6/23  21:12
 * @Version 1.0
 */
@RestController
@RequestMapping("/role")
public class BaseRoleController {
    @Autowired
    BaseRoleService baseRoleService;
    @GetMapping("/initRoles")
    public CommonRespDto initRoles(){
        return CommonRespDto.success(baseRoleService.getAllRoles());
    }
    @PostMapping("/addRoles")
    public RespBean addRoles(@RequestBody Role role){
        if(baseRoleService.addRole(role) == 1 ){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @DeleteMapping("/deleteRole/{rid}")
    public RespBean deleteRoleById(@PathVariable Integer rid){
        if(baseRoleService.deleteRoleById(rid) == 1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @PutMapping("/updateRole/")
    public RespBean updateMenuRole(Integer rid,Integer[] mids){

        if(baseRoleService.updateMenuRole(rid,mids)){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
